package com.appspot.bibtable.model;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import com.appspot.bibtable.model.annotation.AttributeValue;
import com.appspot.bibtable.model.annotation.Input;
import com.appspot.bibtable.model.annotation.Output;
import com.appspot.bibtable.model.annotation.Prototype;
import com.appspot.bibtable.model.format.CollectionFormatter;
import com.appspot.bibtable.model.format.ListParser;

@PersistenceCapable(detachable = "true")
@Prototype("book")
public class Book extends Reference
{
	@Persistent(serialized = "true")
	@Input(name = @AttributeValue(attribute = "editor", display = "Editor"), parser = ListParser.class, elementParserRequired = true, document = "Surname before forename; surname must not be initials and forename can be. Semicolon-separating for more than one. can be put in brackets []. (e.g. Smith J. M.; von Neumann John)")
	@Output(formatter = CollectionFormatter.class)
	private List<String> editor;
	
	@Persistent
	@Input(name = @AttributeValue(attribute = "isbn", display = "ISBN"))
	@Output
	private String isbn;
	
	@Persistent
	@Input(name = @AttributeValue(attribute = "edition", display = "Edition"), document = "Blank for first edition.")
	@Output
	private String edition;
	
	@Persistent
	@Input(name = @AttributeValue(attribute = "publisher", display = "Publisher"))
	@Output
	private String publisher;
	
	public Book()
	{
		editor = new ArrayList<String>();
	}
	
	public List<String> getEditor()
	{
		return editor;
	}
	
	public int getEditorCount()
	{
		return getEditor().size();
	}
	
	public String getEditor(int index)
	{
		return getEditor().get(index);
	}
	
	public void addEditor(String editor)
	{
		getEditor().add(editor);
	}
	
	public void addEditor(int index, String editor)
	{
		getEditor().add(index, editor);
	}
	
	public void removeEditor(String editor)
	{
		getEditor().remove(editor);
	}

	public String getEdition()
	{
		return edition;
	}

	public void setEdition(String edition)
	{
		this.edition = edition;
	}

	public String getPublisher()
	{
		return publisher;
	}

	public void setPublisher(String publisher)
	{
		this.publisher = publisher;
	}

	public String getIsbn()
	{
		return isbn;
	}

	public void setIsbn(String isbn)
	{
		this.isbn = isbn;
	}
}
